<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>员工列表</title>
   <#include "../head.ftl">
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">员工管理</a>
            <a>
              <cite>员工列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="username" placeholder="请输入用户名" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加用户','${basePath}/member/addPage',600,500)"><i
                            class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form" id="userDataTable">
                        <thead>
                        <tr>
                            <th>用户id</th>
                            <th>用户名</th>
                            <th>昵称</th>
                            <th>邮箱</th>
                            <th>角色</th>
                            <th>状态</th>
                            <th>注册时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var userDT = $("#userDataTable").DataTable({
        "processing": true,//等待请求
        "serverSide": false,//开启服务器模式
        "lengthChange": false,//禁用显示改变每页数据条数控件
        "searching": false, //禁用搜索控件
        "ordering": false, //禁用排序功能
        "autoWidth": false,//自动宽度
        "pageLength": 10,
        "ajax": {
            "url": "${basePath}/member/dataList"
        },
        "language": {
            "sSearch": "查询",
            "sZeroRecords": "没有找到记录",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "无记录",
            "sInfoFiltered": "(从 _MAX_ 条记录过滤)",
            "sLoadingRecords": "载入中...",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上一页",
                "sNext": "下一页",
                "sLast": "尾页"
            }
        },
        "columns": [
            {"data": "id"},
            {"data": "userName"},
            {"data": "nickName"},
            {"data": "email"},
            {"data": "role"},
            {
                "data": "status", render: function (data, type, row, meta) {
                    if (data == 1) {
                        return '<span class="layui-btn layui-btn-normal layui-btn-mini" onclick="member_stop(this,' + row.id + ')" status="1" href="javascript:;">已启用</span>';
                    }
                    return '<span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled" onclick="member_stop(this,' + row.id + ')" status="0" href="javascript:;" >已停用</span>';
                }
            }
            ,
            {
                "data": "regTime", render: function (data, type, row, meta) {
                    return dateForamtToString(new Date(data), 'yyyy-MM-dd HH:mm:ss');
                }
            },
            {
                "data": null, render: function (data, type, row, meta) {
                    var v2 = '<a title="编辑" onclick="xadmin.open(\'编辑\',\'${basePath}/member/editPage?uid=' + row.id + '\',600,500)" href="javascript:;"><i class="layui-icon"></i></a>'
                    var v3 = '<a title="删除" onclick="member_del(this,' + row.id + ')" href="javascript:;"><i class="layui-icon"></i></a>';
                    return v2 + v3;
                }
            }
        ]
    });

    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    function member_stop(obj, id) {
        var status = $(obj).parents("td").find('span').attr("status");
        layer.confirm(status == 1 ? '确认要停用吗' : '确认要启用吗', function (index) {
            if (status == 1) {
                $(obj).parents("td").find('span').addClass('layui-btn-disabled').html('已停用');
                $(obj).parents("td").find('span').attr("status", 0);
                layer.msg('已停用!', {icon: 5, time: 1000});
            } else {
                $(obj).parents("td").find('span').removeClass('layui-btn-disabled').html('已启用');
                $(obj).parents("td").find('span').attr("status", 1);
                layer.msg('已启用!', {icon: 5, time: 1000});
            }
            $.get("${basePath}/member/updateStatus?uid=" + id + "&status=" + (status == 1 ? 0 : 1));
        });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.get("${basePath}/member/del?id=" + id, function (rs) {
                var res = eval('(' + rs + ')');
                if (res.status == 200) {
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!', {icon: 1, time: 1000});
                } else {
                    layer.alert(res.message);
                }
                $("#userType").prop("disabled", true);
            });
        });
    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</html>